package com.homedo.odin.solution.enumcode.other;

import com.homedo.core.common.base.dto.Meta;
import com.homedo.core.common.exception.BizException;

/**
 * @author: zhaoxudong
 * @date: 2018/3/9 17:08
 * @Description: 用户积分明细
 */
public enum ScoreRuleEnum {
    /**
     * 签到
     */
    SingIn(1, 2, Integer.MAX_VALUE),
    /**
     * 上传方案
     */
    Sol(2, 20, 5),
    /**
     * 点赞
     */
    Start(3, 1, 5),
    /**
     * 发表评论
     */
    Comment(4, 2, 2),
    /**
     * 邀请用户注册
     */
    Invite(5, 20, 5),
    /**
     * 发布悬赏
     */
    Bounty(6, 2, 5);
    /**
     * 获取积分方式
     */
    private Integer type;
    /**
     * 分值
     */
    private Integer score;

    /**
     * 有效次数
     */
    private Integer limit;

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Integer getScore() {
        return score;
    }

    public void setScore(Integer score) {
        this.score = score;
    }

    public Integer getLimit() {
        return limit;
    }

    public void setLimit(Integer limit) {
        this.limit = limit;
    }

    ScoreRuleEnum(Integer type, Integer score, Integer limit) {
        this.type = type;
        this.score = score;
        this.limit = limit;
    }

    public static ScoreRuleEnum getScoreRuleEnum(Integer type) {
        for (ScoreRuleEnum ruleEnum : values()) {
            if (ruleEnum.getType().equals(type)) {
                return ruleEnum;
            }
        }
        //如果没有找到对应的枚举，说明积分类型传的有问题
        throw new BizException(Meta.CODE_451.getCode(), "积分类型不正确");
    }
}
